-
Notifications
You must be signed in to change notification settings - Fork 10k
add agents x402 docs #25326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add agents x402 docs #25326
Conversation
src/content/docs/agents/x402.mdx
Outdated
| onStart() { | ||
| // We instantiate a wallet from which the agent will pay | ||
| const pk = process.env.CLIENT_TEST_PK as `0x${string}`; | ||
| const agentAccount = privateKeyToAccount(pk); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be called "wallet"?
(Since that's how it is described in the sentence above the code snippet and is most specific)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not entirely sure on the difference on wallet vs account. Since the x402 types are Account I'll stick to that wording. I've updated the comments to make it more clear as well.
src/content/docs/agents/x402.mdx
Outdated
| fetchWithPay!: ReturnType<typeof wrapFetchWithPayment>; | ||
|
|
||
| onStart() { | ||
| // We instantiate a wallet from which the agent will pay |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // We instantiate a wallet from which the agent will pay | |
| // Create a temporary wallet that the agent will use to pay |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding is this is a temporary wallet. Yes? No?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, privateKeyToAccount is deterministic and always derives the same wallet (I'm not sure of the naming either) from a given private key.
So what's expected is that you only need to load your private key into your Worker's secrets and your wallet will be ready to use.
src/content/docs/agents/x402.mdx
Outdated
| const url = new URL(req.url); | ||
| console.log("Trying to fetch paid API"); | ||
|
|
||
| // We use the x402 fetch to access our paid endpoint |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // We use the x402 fetch to access our paid endpoint | |
| // Use the x402 compatible fetch (fetchWithPay) to access the paid endpoint |
| // The first parameter becomes the confirmation callback. | ||
| // We can set it to `null` if we want the agent to pay automatically. | ||
| const res = await this.x402Client.callTool(this.onPaymentRequired, { | ||
| name: toolName, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be an example tool? Otherwise I read this and wondered what this was referencing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added toolName and toolArgs as parameters to fix this
src/content/docs/agents/x402.mdx
Outdated
| } | ||
|
|
||
| onPaymentRequired(paymentRequirements): Promise<boolean> { | ||
| // Your HIL confirmation flow... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's HIL?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Human-in-the-loop", updated it to use that instead to make it more clear
| } | ||
| ``` | ||
|
|
||
| We also include an MCP client that you can use from anywhere (not just your Agents!) to pay for these tools. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where would someone use this outside of an agent? Example might help
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any application that connects to MCP servers is using some version of an MCP client. The wrapper agents wraps the official MCP client to support paid tool calls (which are not officially part of the spec)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e.g. Windsurf wants to support MCPs with paid tools, so they'll need an MCP client that can handle payments
| const X402_CONFIG: X402Config = { | ||
| network: "base", | ||
| recipient: env.MCP_ADDRESS, | ||
| facilitator: { url: "https://x402.org/facilitator" }, // Payment facilitator URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this something that I need to set myself or do I just use this URL as the default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK this one is the official (?) supported payment facilitator that handles payment verifications/settling for servers, and should work for most networks. Some users might want to use different facilitators so they could update it.
In any case, I've added an inline comment to docs on facilitators (https://x402.gitbook.io/x402/core-concepts/facilitator)
irvinebroque
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stamp so you have it, see comments
Co-authored-by: Brendan Irvine-Broque <[email protected]>
Co-authored-by: Brendan Irvine-Broque <[email protected]>
|
let's land this tomorrow right before the announcement |
Summary
Screenshots (optional)
Documentation checklist